package tech.yangzhijie.blog.admin.controller;

import org.springframework.web.bind.annotation.*;
import tech.yangzhijie.blog.admin.entity.SystemPermission;
import tech.yangzhijie.blog.admin.entity.SystemRole;
import tech.yangzhijie.blog.admin.service.SystemPermissionService;
import tech.yangzhijie.blog.admin.service.SystemRoleService;

import java.util.List;

/**
 * @Author: 探险家劫
 * @Date: 2021/11/19 11:10
 */
@RestController
@RequestMapping("/permission")
public class SystemPermissionController {

    private final SystemPermissionService service;

    public SystemPermissionController(SystemPermissionService service) {
        this.service = service;
    }

    @GetMapping
    public List<SystemPermission> get(){
        return service.list();
    }

    @PostMapping
    public String save(SystemPermission systemRole){
        return service.save(systemRole)?"添加成功！":"添加失败！";
    }

    @PutMapping
    public String update(SystemPermission updatedPermission){
        SystemPermission systemPermission = service.getById(updatedPermission.getId());
        if(systemPermission == null) return "修改失败！不存在该用户";
        return service.updateById(updatedPermission)?"修改成功":"修改失败";
    }

    @DeleteMapping("/{id}")
    public String delete(@PathVariable Integer id){
        return service.removeById(id)?"删除成功":"删除失败";
    }
}
